{{extend '../_layouts/home.html'}}

{{block 'title'}}{{'多人博客 - 首页'}}{{/block}}

{{block 'body'}}
<section class="container">
  <div class="row">
    <div class="col-md-5">
      <form id="save">
        <div class="form-group">
          <label for="exampleInputEmail1">选择板块</label>
          <select class="form-control" id="select">
            {{ each topic }}
              <option value="{{ $value._id }}">{{ $value.title }}</option>
            {{ /each }}
            <!-- <option>分享</option>
            <option>问答</option>
            <option>招聘</option>
            <option>客户端测试</option> -->
          </select>
        </div>
        <input type="hidden" name="plate_id" id="plate_id" value="{{ topic[0]._id }}">
        <div class="form-group">
          <label for="exampleInputEmail1">标题</label>
          <input type="text" class="form-control" name="title" placeholder="请输出标题">
        </div>
        <div class="form-group">
          <label for="exampleInputPassword1">内容</label>
          <textarea class="form-control" rows="3" name="content" placeholder="请输出内容"></textarea>
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
    </div>
  </div>
</section>
<script src="/node_modules/jquery/dist/jquery.js"></script>
<script>
  $('#select').on('change',function () {//监听select的改变
    $('#plate_id').val($('#select').val())
  })

   // 保存信息
   $('#save').on('submit', function (e) {
      e.preventDefault()
      var formData = $(this).serialize()
      $.ajax({
        url: '/topics/new',
        type: 'post',
        data: formData,
        dataType: 'json',
        success: function (data) {
          if(data.err_code === 200){
            window.alert('修改成功')
            window.location.href = '/'
          }else{
            window.alert('修改失败')
          }
        }
      })
    })
</script>
{{/block}}
